// pages/myCollection/index.js
const api = require('../../config/api')
const request = require('../../utils/request')
import lottie from '../../utils/lottie'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.init1()
    this.init2()
  },
  // 初始化加载动画
  init1() {
    if (this.inited1) {
      return
    }
    wx.createSelectorQuery()
      .selectAll('#interest_lott1')
      .node((res) => {
        const canvas = res[0].node
        const context = canvas.getContext('2d')
        canvas.width = 300
        canvas.height = 300
        lottie.setup(canvas)
        this.ani = lottie.loadAnimation({
          loop: true,
          autoplay: true,
          animationData: require('./data.js'),
          rendererSettings: {
            context,
          },
        })
        this.inited1 = true
      })
      .exec()
  },
  // 初始化加载动画
  init2() {
    if (this.inited2) {
      return
    }
    wx.createSelectorQuery()
      .selectAll('#interest_lott2')
      .node((res) => {
        const canvas = res[0].node
        const context = canvas.getContext('2d')
        canvas.width = 300
        canvas.height = 300
        lottie.setup(canvas)
        this.ani = lottie.loadAnimation({
          loop: true,
          autoplay: true,
          animationData: require('./data.js'),
          rendererSettings: {
            context,
          },
        })
        this.inited2 = true
      })
      .exec()
  },
  async getList() {
    const res = await request.get(api.getSpecialTraining, {
      type: 'cognitive',
    })
    if (res.httpStatus === 200) {
      this.setData({
        dataList: res.data,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
})
